package com.frank.loadinglibrary.utils;

import ohos.agp.render.PixelMapHolder;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.global.resource.Resource;
import ohos.media.image.ImageSource;
import ohos.media.image.PixelMap;

import java.io.IOException;

public class PxiMapUtils {

    private PxiMapUtils() {
        //do nothing
    }

    public static PixelMapHolder getPixMapHold(Context ctx, int id) throws IOException, NotExistException {
        Resource media = ctx.getResourceManager().getResource(id);
        ImageSource.SourceOptions Soptions = new ImageSource.SourceOptions();
        ImageSource imageSource = ImageSource.create(media, Soptions);
        ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions();
        PixelMap pix = imageSource.createPixelmap(decodingOptions);

        return new PixelMapHolder(pix);
    }
}
